package com.init.bootframe.system.controller;

import com.init.bootframe.system.service.IOrgService;
import com.init.bootframe.system.vo.OrgVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/org")
public class OrgController {

    @Autowired
    private IOrgService orgService; //组织dao

    /**
     * 组织列表查询
     * @param orgVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findOrgList")
    public List<OrgVO> findOrgList(@RequestBody OrgVO orgVO) throws Exception {
        List<OrgVO> result = orgService.findOrgList(orgVO);
        return result;
    }

    /**
     * 添加组织
     * @param orgVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addOrg")
    public Map<String, Object> addOrg(@RequestBody OrgVO orgVO) throws Exception {
        Map<String, Object> result = orgService.addOrg(orgVO);
        return result;
    }

    /**
     * 编辑组织
     * @param orgVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateOrg")
    public Map<String, Object> updateOrg(@RequestBody OrgVO orgVO) throws Exception {
        Map<String, Object> result = orgService.updateOrg(orgVO);
        return result;
    }

    /**
     * 修改批量组织
     * @param orgJson
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/updateBatchOrg",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Map<String, Object> updateBatchOrg(@RequestBody String orgJson) throws Exception {
        Map<String, Object> result = orgService.updateBatchOrg(orgJson);
        return result;
    }

    /**
     * 组织查询
     * @param orgVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findOrg")
    public OrgVO findOrg(@RequestBody OrgVO orgVO) throws Exception {
        OrgVO result = orgService.findOrg(orgVO);
        return result;
    }

    /**
     * 删除组织
     * @param orgVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteOrg")
    public Map<String, Object> deleteOrg(@RequestBody OrgVO orgVO) throws Exception {
        Map<String, Object> result = orgService.deleteOrg(orgVO);
        return result;
    }

    /**
     * 查询树状组织信息集合
     * @param parmOrgVO
     * @return
     * @throws Exception
     */
    @PostMapping("/getOrgsTreeList")
    public List<OrgVO> getOrgsTreeList(@RequestBody OrgVO parmOrgVO) throws Exception {
        List<OrgVO> result = orgService.getOrgsTreeList(parmOrgVO);
        return result;
    }
}
